package tc.maas.bulkfilerenamer.domain.dataobjects;

import tc.maas.bulkfilerenamer.domain.filemanagement.interfaces.Containable;
import tc.maas.bulkfilerenamer.utils.texts.ErrorMessages;

public class File extends AbstractRenamable implements Containable {

    private String prefix;
    private String suffix;

    public File(final java.io.File file) {
        super();
        if (file.isFile()) {
            name = file.getName();
            absolutePath = file.getAbsolutePath();
            divideName();
        } else {
            throw new IllegalArgumentException(ErrorMessages.NOT_A_FILE_ERROR.getMessage());
        }
    }

    private void divideName() {
        suffix = name.substring(name.lastIndexOf(".") + 1);
        prefix = name.substring(0, name.lastIndexOf("."));
    }

    @Override
    public String getPrefix() {
        return prefix;
    }

    @Override
    public String getSuffix() {
        return suffix;
    }

    @Override
    public void updateDelimiters() {
        String name = this.name;
        this.name = prefix;
        super.updateDelimiters();
        this.name = name;
    }
}
